package com.imooc.concurrent.threadAndRunnable;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Runnable能被多个线程共享，并且容易扩展
 */
public class RunnableDemo {

    public static void main(String[] args) {
        MyRunnable myThread = new MyRunnable();

        Thread myThread1 = new Thread(myThread, "窗口1");
        Thread myThread2 = new Thread(myThread, "窗口2");
        Thread myThread3 = new Thread(myThread, "窗口3");

        myThread1.start();
        myThread2.start();
        myThread3.start();
    }
}

class MyRunnable implements Runnable{
    private int ticketsCont = 5;//一共有5张火车票

    @Override
    public void run() {
        while (ticketsCont>0){
            System.out.println(Thread.currentThread().getName()+"卖了一张票，剩余票数为:"+ --ticketsCont);
            Thread.yield();
        }
    }
}
